package practice;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class NavigationTest {
	WebDriver driver;
	@Before
	public void startUp(){
		WebDriver driver = new FirefoxDriver();
		this.driver = driver;
	}

	@Test
	public void testNavigateTo() {
		driver.navigate().to("http://compendiumdev.co.uk/selenium ");
		assertTrue("The title is not started with Selenium Simplified",driver.getTitle().startsWith("Selenium Simplified"));
	}
	@Test
	public void testNavigateForwardAndBack() {
		driver.navigate().to("http://compendiumdev.co.uk/selenium/search.php");
		assertEquals("Selenium Simplified Search Engine",driver.getTitle());
		driver.navigate().to("http://compendiumdev.co.uk/selenium/basic_html_form.html");
		assertEquals("HTML Form Elements",driver.getTitle());
		driver.navigate().back();
		assertEquals("Selenium Simplified Search Engine",driver.getTitle());
		driver.navigate().forward();
		assertEquals("HTML Form Elements",driver.getTitle());	
	}
	@Test
	public void testRandomTitle(){
		driver.navigate().to("http://compendiumdev.co.uk/selenium/refresh.php");
		String firstTitle = driver.getTitle();
		driver.navigate().refresh();
		String secondTitle = driver.getTitle();
		assertFalse("The title was not refreshed", firstTitle.equals(secondTitle));
	}
	@After
	public void tearDown(){
		driver.close();
	}
	

}
